package com.ericsson.enap.modules.cdr.task;

import com.ericsson.common.quartz.task.ManualTask;
import com.ericsson.common.util.LogFileName;
import com.ericsson.common.util.LoggerUtils;
import com.ericsson.enap.modules.cdr.entity.CdrCg;
import com.ericsson.enap.modules.cdr.service.CdrDownloadService;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.List;

/**
 * ims话单下载
 */
@Component
public class ImsCgCdrDownLoadTask implements ManualTask {
    private Logger log = LoggerUtils.Logger(LogFileName.ImsCdrDownLoadJob);
    @Autowired
    private CdrDownloadService cdrDownloadService;
    @Value("${collectorIp}")
    private String collectorIp;
    @Value("${baseDir}")
    private String baseDir;
    @Value("${cdrDataDir}")
    private String cdrDataDir;
    @Value("${imscdrDownloadDir}")
    private String cdrDownloadDir;
    @Value("${imscdrDownloadInterval}")
    private String imscdrDownloadInterval;

    @Override
    public void execute() {
        log.info("ImsCgCdrDownLoadTask execute start");
        String imsDownloadDir=this.baseDir+ File.separator+this.cdrDataDir+File.separator+this.cdrDownloadDir;
        //根据采集器IP查询对应下载的IMSCG
        List<CdrCg> cdrCgs= cdrDownloadService.getCgList(2,104,this.collectorIp);
        log.info("ImsCgCdrDownLoadTask execute imsCgs size:"+cdrCgs.size());
        if(cdrCgs.size()>0){
            cdrDownloadService.downloadCgCDRFile(2,cdrCgs,imsDownloadDir,imscdrDownloadInterval);
        }
        log.info("ImsCgCdrDownLoadTask execute end");
    }
}
